#include <iostream>
#include<vector>
#define maxsize 100
using namespace  std;
bool visited[maxsize];
// 图的邻接表形式 图的顶点数边数  顶点表 边节点
typedef struct ArcNode
{
    int i;
    struct ArcNode* next;
}ArcNode ;

typedef struct Vnode
{
   struct ArcNode* firstArcNode;
}VNode,Adjlist[maxsize];

typedef  struct Graph
{
   int vexnum,arcnum;
   Adjlist adjlist;// Vnode adjlist[20];
};
void printV(vector<int >&v)
{
    for(int i=0;i<v.size();++i)
        cout<<v[i];
    cout<<endl;
}
Graph graph;

void dfs(int i,int j,vector<int> &v)
{

     visited[i]=true;
     v.push_back(i);
     if(i==j) //如果是终点就打印路径
     {
         printV(v);
         visited[i]=false;
         v.pop_back();
         return ;
     }
     ArcNode* p=graph.adjlist[i].firstArcNode;
     while(p!=NULL)
     {
         if(visited[p->i]==false)
         {
             dfs(p->i,j,v);
         }
         p=p->next;
     }
     v.pop_back();
     visited[i]=false;

}

void mydfs(int i)
{
    visited[i]=true;
    cout<<i<<" ";
    ArcNode* p=graph.adjlist[i].firstArcNode;
    while(p)
    {
        if(!visited[p->i])
          mydfs(p->i);
        p=p->next;
    }
}
int main() {
   //初始化图
   int vexnum,arcnum;
   cin>>vexnum>>arcnum;
   graph.arcnum=arcnum;
   graph.vexnum=vexnum;
   //边表置空
   for(int i=1;i<=vexnum;++i)
   {
       graph.adjlist[i].firstArcNode=NULL;
   }


   for(int i=1;i<=arcnum;++i)
   {
       int a,b;
       cin>>a>>b;
      ArcNode*  insertNode=(ArcNode*)malloc(sizeof(ArcNode));
       insertNode->i=b;
       insertNode->next=NULL;

       //采用头插法
       if(graph.adjlist[a].firstArcNode==NULL)
       {
           graph.adjlist[a].firstArcNode=insertNode;
       }
       else
       {
           insertNode->next=graph.adjlist[a].firstArcNode;
           graph.adjlist[a].firstArcNode=insertNode;
       }
   }


//
   //初始化visited数组
  for(int i=1;i<=vexnum;++i)
      visited[i]=false;
   //dfs遍历
   vector <int> v;
   //从第一个节点出发
   dfs(1,6,v);
//  mydfs(1);


    return 0;
}
